getnameinfo

getnameinfo translates a socket address to a node name and service location, all of which are defined as in getaddrinfo.

Syntax

int WSAAPI getnameinfo(
    const struct sockaddr FAR *sa,
    socklen_t salen,
    char FAR *host,
    DWORD hostlen,
    char FAR *serv,
    DWORD servlen,
    int flags
);

Parameters

sa

A pointer to a socket address structure to be translated.

salen

Size of the socket address structure pointed by sa.

host

A pointer to a zero-terminated ASCII string containing the host name.

hostlen

The length of the buffer pointed to by the node parameter, in bytes. The caller must provide a buffer large enough to hold the host name, including terminating NULL characters. A value of zero indicates the caller does not want to receive the string provided in host.

serv

A pointer to a zero-terminated ASCII string containing the service name associated with the port number.

servlen

Length of the buffer pointed to by the serv parameter, in bytes. The caller must provide a buffer large enough to hold the service name, including terminating null characters. A value of zero indicates the caller does not want to receive the string provided in serv.

flags

The flags argument modifies the behaviour of getnameinfo as follows:

Flag Description

NI_NUMERICHOST

If set, then the numeric form of the hostname is returned.

NI_NUMERICSERV

If set, then the service address is returned in numeric form, for example by its port number.

Return Value

0 (zero) if the function succeeds, a non-zero positive value if the function fails

Error codes returned by getnameinfo can also map to any of following:

Error Code Description
WSATRY_AGAIN

The name could not be resolved at this time. Try again later.

WSAEINVAL

ai_flags contains invalid flags.

WSAEAFNOSUPPORT

The requested address family is not supported.

WSA_NOT_ENOUGH_MEMORY

Memory allocation failure.

WSAHOST_NOT_FOUND

The name does not resolve for the supplied parameters.

WSANO_RECOVERY

A non-recoverable error occurred.

Requirements

Minimum Supported Version RTX64 2013
Header Ws2tcpip.h
Library RtTcpip.lib